/**
 * 工具类
 */
 
// 深拷贝
export function deepClone(obj) {
  let newObj = Array.isArray(obj) ? [] : {}
  if (obj && typeof obj === 'object') {
    for (let key in obj) {
      if (obj.hasOwnProperty(key)) {
        newObj[key] = (obj && typeof obj[key] === 'object') ? deepClone(obj[key]) : obj[key]
      }
    }
  }
  return newObj
}

// 等比缩放图片
export function resetSize(vm, opt, fn) {
  let width = vm.$el.offsetWidth || parseInt(vm.setSize.imgWidth)
  let height = vm.$el.offsetHeight || parseInt(vm.setSize.imgHeight)
  
  return {
    width: width + 'px',
    height: height + 'px'
  }
}

// 函数节流
export function debounce(fn, delay = 200) {
  let timer = null
  return function() {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(this, arguments)
    }, delay)
  }
} 